const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const resolve = (p) => path.resolve(__dirname, p);

module.exports = {
    mode: 'development',
    entry: resolve('src/index.js'),
    output: {
        path: resolve('dist'),
        filename: 'main.js'
    },
    devtool: 'source-map',
    module: {
        rules: [
            {
                test: /\.jsx?$/,
                use: 'babel-loader'
            }
        ]
    },
    resolve: {
        extensions: ['.js', '.jsx'],
        alias: {
            '@': resolve('src')
        }
    },
    devServer: {
        port: 3000,
        hot: true,
        compress: true,
        historyApiFallback: true // 使用路由history模式的时候要开启，否则找不到页面
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: resolve('public/index.html')
        })
    ]
}